package com.ymttest.common.order.userquery.model.vo;


import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import com.ymt.core.tool.Logger;
import com.ymttest.utils.DataUtil;

/**
 * 订单信息
 * 
 * @author luoshiqian 2016/12/28 14:14
 */
public class OrderInfo {


    /**
     * 主单号
     */
    public long orderGroupId;


    /**
     * 下单后未付款多久自动取消订单
     */
    public BigDecimal autoCancelOrderHours;


    /**
     * 订单id
     */
    public long orderId;


    /**
     * 下单时间
     */
    public Date addTime;


    /**
     * 订单来源平台 PlatformEnum
     */
    public int platform;


    /**
     * 是否扫货订单
     */
    public boolean shangou;


    /**
     * 订单取消原因
     */
    public String cancelReason;


    /**
     * 订单是否已评价(分)
     */
    public boolean evaluated;


    /**
     * 订单相关状态信息
     */
    public StatusInfo status;


    /**
     * 卖家信息
     */
    public SellerInfo seller;


    /**
     * 买家信息
     */
    public OrderConsumerInfo consumer;


    /**
     * 商品信息
     */
    public List<ProductInfo> products;


    /**
     * 收货人信息
     */
    public OrderConsigneeInfo consignee;


    /**
     * 支付信息
     */
    public PaymentInfo payment;


    /**
     * 收货、退货信息
     */
    public TransferInfo transfer;

    /**
     * 能否评价
     */
    public boolean canEvaluate;

    /**
     * 是否预售订单
     */
    public boolean preSaleOrder;

    /**
     * 是否国内已发货（拼邮）
     */
    public boolean domesticDelivered;

    /**
     * 订单当前状态下的可操作信息. null表示不能进行操作
     */
    public OrderOperationInfo operation;
    /**
     * 砍价团信息
     */
    private BargainGroupInfo bargainGroup;

    public long getOrderGroupId() {
        return orderGroupId;
    }

    public void setOrderGroupId(long orderGroupId) {
        this.orderGroupId = orderGroupId;
    }

    public BigDecimal getAutoCancelOrderHours() {
        return autoCancelOrderHours;
    }

    public void setAutoCancelOrderHours(BigDecimal autoCancelOrderHours) {
        this.autoCancelOrderHours = autoCancelOrderHours;
    }

    public long getOrderId() {
        return orderId;
    }

    public void setOrderId(long orderId) {
        this.orderId = orderId;
    }

    public Date getAddTime() {
        return addTime;
    }

    public void setAddTime(Date addTime) {
        this.addTime = addTime;
    }

    public int getPlatform() {
        return platform;
    }

    public void setPlatform(int platform) {
        this.platform = platform;
    }

    public boolean isShangou() {
        return shangou;
    }

    public void setShangou(boolean shangou) {
        this.shangou = shangou;
    }

    public String getCancelReason() {
        return cancelReason;
    }

    public void setCancelReason(String cancelReason) {
        this.cancelReason = cancelReason;
    }

    public boolean isEvaluated() {
        return evaluated;
    }

    public void setEvaluated(boolean evaluated) {
        this.evaluated = evaluated;
    }

    public StatusInfo getStatus() {
        return status;
    }

    public void setStatus(StatusInfo status) {
        this.status = status;
    }

    public SellerInfo getSeller() {
        return seller;
    }

    public void setSeller(SellerInfo seller) {
        this.seller = seller;
    }

    public OrderConsumerInfo getConsumer() {
        return consumer;
    }

    public void setConsumer(OrderConsumerInfo consumer) {
        this.consumer = consumer;
    }

    public List<ProductInfo> getProducts() {
        return products;
    }

    public void setProducts(List<ProductInfo> products) {
        this.products = products;
    }

    public OrderConsigneeInfo getConsignee() {
        return consignee;
    }

    public void setConsignee(OrderConsigneeInfo consignee) {
        this.consignee = consignee;
    }

    public PaymentInfo getPayment() {
        return payment;
    }

    public void setPayment(PaymentInfo payment) {
        this.payment = payment;
    }

    public TransferInfo getTransfer() {
        return transfer;
    }

    public void setTransfer(TransferInfo transfer) {
        this.transfer = transfer;
    }

    public OrderOperationInfo getOperation() {
        return operation;
    }

    public void setOperation(OrderOperationInfo operation) {
        this.operation = operation;
    }

    public boolean isCanEvaluate() {
        return canEvaluate;
    }

    public void setCanEvaluate(boolean canEvaluate) {
        this.canEvaluate = canEvaluate;
    }

    public boolean isPreSaleOrder() {
        return preSaleOrder;
    }

    public void setPreSaleOrder(boolean preSaleOrder) {
        this.preSaleOrder = preSaleOrder;
    }

    public boolean isDomesticDelivered() {
        return domesticDelivered;
    }

    public void setDomesticDelivered(boolean domesticDelivered) {
        this.domesticDelivered = domesticDelivered;
    }
    
	public BargainGroupInfo getBargainGroup() {
		return bargainGroup;
	}

	public void setBargainGroup(BargainGroupInfo bargainGroup) {
		this.bargainGroup = bargainGroup;
	}
    
    public void verify(OrderInfo actual){
		Logger.comment(String.format("校验订单号: %d的OrderInfos", this.getOrderId()));
		boolean isSameOrder = this.getOrderId() == actual.getOrderId();
		if(isSameOrder){
			DataUtil.verifyObject(this, actual, "OrderInfos");
			Logger.comment(String.format("校验订单号: %d的OrderInfos.Status", this.getOrderId()));
			DataUtil.verifyObject(this.getStatus(), actual.getStatus(), "OrderInfos.Status");
			Logger.comment(String.format("校验订单号: %d的OrderInfos.Seller", this.getOrderId()));
			if (this.getSeller() == null) {
				DataUtil.verify(null, actual.getSeller(), "验证OrderInfos.Seller == null");
			}else{
				DataUtil.verifyObject(this.getSeller(), actual.getSeller(), "OrderInfos.Seller");
			}
			Logger.comment(String.format("校验订单号: %d的OrderInfos.Consumer", this.getOrderId()));
			if (this.getConsumer() == null) {
				DataUtil.verify(null, actual.getConsumer(), "验证OrderInfos.Consumer == null");
			}else{
				DataUtil.verifyObject(this.getConsumer(), actual.getConsumer(), "OrderInfos.Consumer");
			}
			Logger.comment(String.format("校验订单号: %d的OrderInfos.Products", this.getOrderId()));
			if (DataUtil.isNullOrEmpty(this.getProducts())) {
				DataUtil.verify(null, actual.getProducts(), "验证OrderInfos.Products == null或者OrderInfos.Products.size() == 0");
			}else {
				for(int j=0;j<this.getProducts().size()-1 ;j++){
					Logger.comment(String.format("校验订单号: %d的OrderInfos.Products[%d]", this.getOrderId(), j));
					DataUtil.verifyObject(this.getProducts().get(j), actual.getProducts().get(j), String.format("OrderInfos.Products[%d]", j));
				}
			}
			
			Logger.comment(String.format("校验订单号: %d的OrderInfos.Consignee", this.getOrderId()));
			if (this.getConsignee() == null) {
				DataUtil.verify(null, actual.getConsignee(), "验证OrderInfos.Consignee == null");
			}else {
				DataUtil.verifyObject(this.getConsignee(), actual.getConsignee(), "OrderInfos.Consignee");
			}
			
			Logger.comment(String.format("校验订单号: %d的OrderInfos.Payment", this.getOrderId()));
			if(this.getPayment() == null){
				DataUtil.verify(true, actual.getPayment().getDetail(), "验证OrderInfos.Payment == null");
			}else{
				DataUtil.verifyObject(this.getPayment(), actual.getPayment(), "OrderInfos.Payment");
				Logger.comment(String.format("校验订单号: %d的OrderInfos.Payment.Detail", this.getOrderId()));
				if(this.getPayment().getDetail() == null){
					DataUtil.verify(null, actual.getPayment().getDetail(), "验证OrderInfos.Payment.Detail == null");
				}else{
					if(this.getPayment().getDetail().getEarnest() == null){
						DataUtil.verify(null, actual.getPayment().getDetail().getEarnest(), "验证OrderInfos.Payment.Detail.Earnest == null");
					}else{
						DataUtil.verifyObject(this.getPayment().getDetail().getEarnest(), actual.getPayment().getDetail().getEarnest(), "OrderInfos.Payment.Detail.Earnest");
					}
				}
			}
	
			Logger.comment(String.format("校验订单号: %d的OrderInfos.Transfer", this.getOrderId()));
			if (this.getTransfer() == null) {
				DataUtil.verify(null, actual.getTransfer(), "验证OrderInfos.Transfer == null");
			}else{
				DataUtil.verifyObject(this.getTransfer(), actual.getTransfer(), "OrderInfos.Transfer");
			}
			
			Logger.comment(String.format("校验订单号: %d的OrderInfos.Operation", this.getOrderId()));
			if (this.getOperation()!=null){
				/*
				 * 暂时不验证，之后再改
				 */
	//			DataUtil.verifyObject(this.getOperation(), actual.getOperation(), "OrderInfos.Operation");
			}
			else {
				DataUtil.verify(null, actual.getOperation(),"验证 OrderInfos.Operation == null");
			}
			
			Logger.comment(String.format("校验订单号: %d的砍价团信息OrderInfos.BargainGroup", this.getOrderId()));
			if(this.getBargainGroup() == null){
				DataUtil.verify(null, actual.getBargainGroup(), String.format("验证订单id:%d 没有参加砍价团(orderInfos.bargainGroup == null)", this.getOrderId()));
			}else{
				DataUtil.verifyObject(this.getBargainGroup(), actual.getBargainGroup(), "砍价团信息orderInfos.bargainGroup");
			}
		}else{
			DataUtil.verify(this.getOrderId(), actual.getOrderId(), "验证订单id");
		}
    }


}
